<%@ page contentType="text/html;charset=UTF-8" language="java"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<link href="<c:url value='/css/default.css'/>" rel="stylesheet"
	type="text/css" />

<head>

<fmt:setBundle basename="lang.message" />

<c:set var="t" value="true" />

<jsp:include page="Redir.jsp"></jsp:include>



<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title><fmt:message key="general.title" /> - <fmt:message
		key="user.title" /></title>

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>

<script type="text/javascript" src="js/NumericOnly.js"></script>

<script type="text/javascript" src="js/jquery.validate.min.js"></script>





<script type="text/javascript">
	(function($, W, D) {

		var JQUERY = {};

		JQUERY.UTIL = {

			setupFormValidation : function() {

				//form validation rules

				$("#UserForm").validate({

					rules : {

						id : "required",

						name : "required",

						password : "required",

						confirm : "required",

						email : {

							required : true,

							email : true

						}

					},

					messages : {

						id : "Enter a user id",

						name : "Enter a name",

						password : "Enter a password",

						confirm : "Confirm your password",

						email : "Enter a correct email"

					},

					submitHandler : function(form) {

						form.submit();

					}

				});

			}

		}

		//when the dom has loaded setup form validation rules document.createElement('script');

		//window.jQuery.fn.jquery------ $("#id").functionname(function(){........});

		$(D).ready(function($) {

			JQUERY.UTIL.setupFormValidation();

		});

	})(jQuery, window, document);
</script>

</head>

<body>

	<%@include file="Header.jsp"%>

	<div id="wrapper">

		<div id="page-wrapper">

			<div id="page">

				<%@include file="Menu.jsp"%>

				<div id="content">

					<form action="ProcessUser" method=post id="UserForm">

						<h2>

							<fmt:message key="user.add" />

						</h2>

						<table class="table-form">

							<tr>

								<td width="130px"><fmt:message key="user.field.id" /></td>

								<td><input type="text" name="id" value="${data.id}"
									size="40" maxlength="20"
									${action == 'edit' ? 'readonly="readonly"' : '' } /> <input
									type="hidden" name="action" value="${action}" /></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.name" /></td>

								<td><input type="text" name="name" value="${data.name}"
									size="40" maxlength="50"></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.type" /></td>

								<td><select name="role" style="width: 228px">

										<option value="Admin"
											${ data.type == 'Admin' ? 'selected="selected"' : '' }>Admin</option>

										<option value="Staff"
											${ data.type == 'Staff' ? 'selected="selected"' : '' }>Staff</option>

										<option value="Manager"
											${ data.type == 'Manager' ? 'selected="selected"' : '' }>Manager</option>

								</select></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.password" /></td>

								<td><input type="password" name="password${action == 'edit' ? '2' : '' }" value=""
									${action == 'edit' ? 'readonly="readonly"' : '' } size="40"
									maxlength="50"></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.confirm" /></td>

								<td><input type="password" name="confirm${action == 'edit' ? '2' : '' }" value=""
									${action == 'edit' ? 'readonly="readonly"' : '' } size="40"
									maxlength="50"></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.email" /></td>

								<td><input type="text" name="email" value="${data.email}"
									size="40" maxlength="50"></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.manager" /></td>

								<td><select name="manager" style="width: 228px">

										<option value="">-</option>

										<c:forEach items="${managers}" var="mngr">

											<c:if test="${data.id != mngr.id}">

												<option value="${mngr.id}"
													${data.managerId == mngr.id ? 'selected="selected"' : ''}>${mngr.name}</option>

											</c:if>

										</c:forEach>

								</select></td>

							</tr>

							<tr>

								<td><fmt:message key="user.field.status" /></td>

								<td><select name="status" style="width: 228px">

										<option value="0"
											${ data.status == 0 ? 'selected="selected"' : '' }>Inactive</option>

										<option value="1"
											${ empty data.status || data.status == 1 ? 'selected="selected"' : '' }>Active</option>

								</select></td>

							</tr>

							<c:if test="${not empty error}">

								<tr>

									<td colspan="2" style="color: red;"><fmt:message
											key="${error}" /></td>

								</tr>

							</c:if>

						</table>

						<input type="submit" value="Submit" class="button-style">

						<input type="reset" value="Reset" name="reset"
							class="button-style-cancel">

					</form>

				</div>

			</div>

		</div>

	</div>

	<%@include file="Footer.jsp"%>

</body>

</html>